import React, { useEffect, useState } from "react";
import { RouterProvider } from "react-router-dom";
import { ConfigProvider } from "antd"
import { router } from "@/router";
import "./App.css";
import { QiankunProps } from "vite-plugin-qiankun/dist/helper";
import { QiankunContext } from "./context/QiankunContext";
import { nanoid } from 'nanoid'
function App(qiankun:QiankunProps) {

  const [ qiankunReady ,setQiankunReady ] = useState<string|null>(null)
  
  useEffect(()=>{
    console.log("子应用加载")
    setQiankunReady(nanoid())
    return ()=>{
      console.log("子应用卸载")
    }
  },[])

  if(!qiankunReady) return <div>Loading...</div>
  
  return (
    <ConfigProvider prefixCls="formily-editor" key={qiankunReady}>
      <QiankunContext.Provider value={qiankun}>
        <RouterProvider router={router} fallbackElement={<div>Loading...</div>} />
      </QiankunContext.Provider>
    </ConfigProvider>
  )
}

export default App;
